package com.kycxika.app.activity.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.Fragment;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
import com.kycxika.app.R;
import com.kycxika.app.activity.MainActivity;
import com.kycxika.app.dbutils.IntImp.KycXkIApi;
import com.kycxika.app.view.CircleImageView;


/**
 * Created by DELL on 2017/5/2.
 */
public class MySelfTwoFragment extends Fragment{

    private View mView;
    private Boolean userRegistionStatu;
    private KycXkIApi api;

    private final String[] data = {"个人信息",
            "系统通知", "系统设置"};

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mView = View.inflate(getActivity(), R.layout.myselef_two_fragment, null);
        initView();
        initData();
        initListener();
        return mView;
    }

    private void initView() {
        Toolbar toolbar = (Toolbar) mView.findViewById(R.id.toolbar);
        //设置ToolBar作为ActionBar
        MainActivity.instance.setSupportActionBar(toolbar);
        // getActivity().setActionBar(toolbar); //.setSupportActionBar(toolbar);
        // ActionBar actionBar = getActivity().getActionBar();
        ActionBar actionBar = MainActivity.instance.getSupportActionBar();
        if (actionBar != null) {
            //设置ActionBar左上角按钮
            CircleImageView circleImageView = new CircleImageView(getContext());
            circleImageView.setImageResource(R.drawable.ce_01);
            actionBar.setHomeAsUpIndicator(R.drawable.ic_launcher);
            actionBar.setDisplayHomeAsUpEnabled(true);
        }
        DrawerLayout drawerLayout = (DrawerLayout) mView.findViewById(R.id.drawer_main);
        FloatingActionButton floatBtn = (FloatingActionButton) mView.findViewById(R.id.float_btn);
        floatBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(getContext(), "Float Button", Toast.LENGTH_SHORT).show();
            }
        });

        RecyclerView recyclerView = (RecyclerView) mView.findViewById(R.id.recycler);
        MyAdapter myAdapter = new MyAdapter();
        recyclerView.setAdapter(myAdapter);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));



        api = new KycXkIApi(getContext());
        userRegistionStatu = api.getUserRegistionStatu();  //判断是否登录

        if(userRegistionStatu) {

        }else {

        }
    }

    private void initData() {

    }

    private void initListener() {

    }

    class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {

        class ViewHolder extends RecyclerView.ViewHolder {
            private TextView tv;

            ViewHolder(View itemView) {
                super(itemView);
                tv = (TextView) itemView.findViewById(R.id.tv);
            }

        }

        @Override
        public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.jp_item_list, parent, false);
            return new ViewHolder(view);
        }

        @Override
        public void onBindViewHolder(ViewHolder holder, int position) {
            holder.tv.setText(data[holder.getAdapterPosition()]);
        }

        @Override
        public int getItemCount() {
            return data.length;
        }
    }

}
